<template>
  <div>
    <form>
      <div class="form-group">
        <label for="c_plan_year">年份：</label>
        <v-select id="c_plan_year" :value.sync="c_plan_year"
        :options='c_year_list' close-on-select clear-button></v-select>
      </div>
    </form>
    <data-grid :model="model" partial='list' v-ref:grid>
      <template partial='head'>
        <tr>
          <th>安检员</th>
          <th>任务</th>
          <th>已完成</th>
          <th></th>
        </tr>
      </template>
      <template partial='body'>
        <td>{{row.f_checker}}</td>
        <td>{{row.task}}</td>
        <td>{{row.accomplished}}</td>
        <td v-on:click.stop.prevent='$parent.$parent.showDetail(row)'>
          <span class="glyphicon glyphicon-option-horizontal"></span>
          <span class="glyphicon glyphicon-hand-left"></span>
          <!-- <img src="../../../static/caozuo.png" width="32" height="22"> -->
        </td>
      </template>
    </data-grid>
    <div style="height:50px;"></div>
  </div>
</template>

<script>
import co from 'co'
import Vue from 'vue'

let aggCheckerTask = function * (self) {
    let result = yield self.$post(Vue.url + 'sql/统计安检员年任务?pageNo=1&pageSize=9999', {
        data: {
            id: Vue.user.id,
            org_id: Vue.user.parentid,
            f_plan_year: self.c_plan_year[0],
            f_subcompany: Vue.user.f_subcompany
        }
    }, {
        resolveMsg: null,
        rejectMsg: '提取任务出错'
    })
    self.$set("model.rows", result.data)
}

export default {
  title: '安检员年任务',
  data() {
    let options = []
    let year = (new Date()).getFullYear()
    options.push({label: year+'', value: year+''})
    year++
    options.push({label: year+'', value: year+''})
    return {
      c_plan_year: options[0].value,
      c_year_list: options,
      model: {
        rows: [],
      }
    }
  },
  ready () {
    this.$watch('c_plan_year', function (val) {
        this.getPlan()
    })
    this.getPlan()
  },
  methods: {
    getPlan () {
      let fp = aggCheckerTask(this)
      co(fp)
    },
    showDetail (row) {
      this.$parent.$goto('checker-annual-detail', {f_plan_year: this.c_plan_year[0], f_checker: row.f_checker}, 'master-router')
    }
  }
}
</script>
